package model;

/**
 * OrderLine.java
 * Purpose: Represents an order line.
 * 
 * @author Michael Adamczyk
 * @version 0.1 10/01/2012
 */

public class OrderLine {
	/* Identifies the order line */
	private long id;
	/* The order to which the line belongs */
	private Order order;
	/* The id of the order */
	private long orderId;
	/* Product ordered */
	private Product product;
	/* The id of the product */
	private long productId;
	/* Quantity ordered */
	private int quantity;
	/* Price of the product */
	private float price;
	
	/** Constructs a new order line */
	public OrderLine() {
	}
	
	/** Constructs a new order line */
	public OrderLine(long id, Product product, int quantity, float price) {
		this.id = id;
		this.product = product;
		this.quantity = quantity;
		this.price = price;
	}
	
	/** Returns the id of the order line */
	public long getId() {
		return id;
	}
	
	/** Sets the id of the order line */
	public void setId(long id) {
		this.id = id;
	}
	
	/** Returns the order to which the line belongs */
	public Order getOrder() {
		return order;
	}

	/** Sets the order to which the line belongs */
	public void setOrder(Order order) {
		this.order = order;
	}
	
	/** Returns the id of the order */
	public long getOrderId() {
		return orderId;
	}

	/** Sets the id of the order */
	public void setOrderId(long orderId) {
		this.orderId = orderId;
	}
	
	/** Returns the product ordered */
	public Product getProduct() {
		return this.product;
	}
	
	/** Sets the product ordered */
	public void setProduct(Product product) {
		this.product = product;
		this.price = this.product.getPrice();
	}
	
	/** Returns the id of the product */
	public long getProductId() {
		return productId;
	}

	/** Sets the id of the product */
	public void setProductId(long productId) {
		this.productId = productId;
	}
	
	/** Returns the quantity ordered */
	public int getQuantity() {
		return this.quantity;
	}
	
	/** Sets the quantity ordered */
	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}
	
	/** Returns the price of the product */
	public float getPrice() {
		return this.price;
	}

	/** Sets the price of the product */
	public void setPrice(float price) {
		this.price = price;
	}

	/** Returns a string representation of the order line */
	@Override
	public String toString() {
		return String.format("%s * %d", this.product.getName(), this.quantity);
	}
}